Component({
  properties: {
    blockColor: {
      type: String,
      value: "url(https://image-classify.daieco.com/kejian-quanzi/QjreT8QQFnji24cc54748cd4343096155175983e38b9.png)"
    },
    blockSize: {
      type: Number,
      value: 36
    },
    backgroundColor: {
      type: String,
      value: "#C6C5C5"
    },
    activeColor: {
      type: String,
      value: "#C6C5C5"
    },
    step: {
      type: Number,
      value: 1
    },
    min: {
      type: Number,
      value: 0
    },
    max: {
      type: Number,
      value: 100
    },
    value: {
      type: Number,
      value: 0
    },
    disabled: {
      type: Boolean,
      value: false
    },
  },
  data: {
    totalTop: null,
    totalHeight: null,
    currentValue: 0,
  },
  methods: {
    setCurrent: function(e){
      this.setData({
        currentValue: e.value
      })
    },
    queryHeight: function(){
      wx.createSelectorQuery().in(this).select('.slider-container').boundingClientRect((res) => {
        this.setData({
          totalTop: res.top,
          totalHeight: res.height
        })
      }).exec()
    },
    // 增加
    plus() {
      const { currentValue } = this.data
      let value = currentValue + 10
      value = value > 100 ? 100 : value
      this.setData({
        value
      })
      this.triggerEvent('change', {
        value
      })
    },
    // 减少
    minus() {
      const { currentValue } = this.data
      let value = currentValue - 10
      value = value < 0 ? 0 : value
      this.setData({
        value
      })
      this.triggerEvent('change', {
        value
      })
    },
    empty: function(){},
  },
  lifetimes: {
    attached () {
      this.queryHeight()
    }
  }
})